home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
Librarys
/
MMULib
/
C_Sources
/
MuRemapTest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-26
|
22KB
|
603 lines
/*************************************************
** MuRemapTest **
** experimental MMU memory remapper **
** **
** This program checks for correctness of the **
** device drivers and correct MMU support **
** **
** Note that device drivers have to call **
** CachePreDMA() and CachePostDMA() to be **
** notified about the TRUE physical addresses **
** some devices might fail here **
** **
** Version 40.0 26 May 1999 **
** © THOR Thomas Richter **
*************************************************/
/// Includes
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/ports.h>
#include <exec/execbase.h>
#include <dos/dos.h>
/* MMU specific includes */
#include <mmu/mmubase.h>
#include <mmu/context.h>
#include <mmu/mmutags.h>
#include <workbench/startup.h>
#include <proto/exec.h>
#include <proto/mmu.h>
#include <proto/dos.h>
#include <proto/icon.h>
#include <string.h>
///
/// Defines
#define STRINGDATE "5.3.99"
#define STRINGVERSION "40.0"
/* Defines for the shell template */
#define TEMPLATE "TEMPFILE/A"
#define OPT_DEVICE 0
#define OPT_WINDOW 1
#define OPT_COUNT 2
///
/// Statics
/* just the library bases */
struct MMUBase *MMUBase;
struct DosLibrary *DOSBase;
struct ExecBase *SysBase;
struct Library *IconBase;
///
/// Protos
/* prototyping */
int __asm __saveds main(void);
struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp);
int CheckRemapping(char *filename);
BOOL SetRemap(struct MMUContext *ctx,struct MemHeader *physical,struct MemHeader *logical,ULONG size);
void FileTest(char *filename,void *physical,void *logical,ULONG size);
BOOL ForceRebuild(struct MMUContext *ctx);
struct MemHeader *MemHeaderOf(void *mem);
///
char version[]="$VER: MuRemapTest " STRINGVERSION " (" STRINGDATE ") © THOR";
/// main
int __asm __saveds main(void)
{
LONG args[OPT_COUNT];
struct RDArgs *rd,*myrd;
struct Process *proc;
int rc=20;
LONG err;
struct WBStartup *msg;
BPTR oldout;
struct MsgPort *oldconsole;
/* This program is compiled without startup code, hence we have
to setup ourselfs */
SysBase=*((struct ExecBase **)(4L));
/* clear the arguments */
memset(args,0,sizeof(LONG)*OPT_COUNT);
/* Wait for the workbench startup, if any */
proc=(struct Process *)FindTask(NULL);
if (!(proc->pr_CLI)) {
WaitPort(&(proc->pr_MsgPort));
msg=(struct WBStartup *)GetMsg(&(proc->pr_MsgPort));
} else msg=NULL;
/* Open the libraries we need */
if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",0L)) {
err=ERROR_REQUIRED_ARG_MISSING;
myrd=NULL; /* reset the temporary ReadArgs */
oldout=NULL;
oldconsole=NULL;
/* Check whether we're run from workbench or
shell. On a WBRun, we parse the tool types
and setup our own output stream, keeping
the old one - which will be NULL anyways... */
if (msg) {
oldout=SelectOutput(NULL);
oldconsole=SetConsoleTask(NULL);
rd=ReadTTArgs(msg,args,&myrd);
} else rd=ReadArgs(TEMPLATE,args,NULL);
if (rd) {
/* Check for a working MMU. The mmu library
will open anyways, even without one. */
if (!GetMMUType()) {
Printf("MuRemapTest requires a working MMU.\n");
err=10;
} else {
/* Argument parser worked, call main routine */
err=CheckRemapping((char *)(args[OPT_DEVICE]));
}
/* Shut down */
FreeArgs(rd);
if (myrd) FreeDosObject(DOS_RDARGS,myrd);
if (msg) Close(SelectOutput(NULL));
} else err=IoErr();
if (msg) {
SelectOutput(oldout);
SetConsoleTask(oldconsole);
}
/* we're done. Check for the result code. If
it is below 64, it is passed over as primary
result code. */
if (err<64) {
rc=err;
err=0;
} else {
if (!msg) PrintFault(err,"MuRemapTest failed");
rc=10;
}
SetIoErr(err);
CloseLibrary((struct Library *)MMUBase);
} else PrintFault(ERROR_OBJECT_NOT_FOUND,"MuRemapTest requires the mmu.library");
CloseLibrary((struct Library *)DOSBase);
}
return rc;
}
///
/// ReadTTArgs
struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp)
{
struct WBArg *wbarg;
struct DiskObject *dop;
char **tt; /* ToolTypes array */
char *wbstr; /* Our self-made workbench argument string */
char *here;
BPTR oldlock;
ULONG len;
struct RDArgs *rd=NULL,*myrd=NULL;
LONG err=0;
BPTR newout;
/* Parse the tool type string for arguments...
this is mainly Mike's code. */
if (IconBase=OpenLibrary("icon.library",37L)) {
if (wbarg=msg->sm_ArgList) {
/* use a project icon if there is one... */
if (msg->sm_NumArgs > 1) wbarg++;
/* go into the directory */
oldlock=CurrentDir(wbarg->wa_Lock);
if (dop=GetDiskObject(wbarg->wa_Name)) {
if (tt=dop->do_ToolTypes) {
/* Read a special tool type for the output window */
/* Calc the size of the argument string */
len = 3; /* reserve space for SPC,LF,NUL */
while (*tt) {
len += strlen(*tt)+1; /* string, plus space */
tt++;
}
if (wbstr=AllocVec(len,MEMF_PUBLIC)) {
/* Now copy the arguments into this string, one by one
and check whether the argument string is still valid. */
tt=dop->do_ToolTypes;
here=wbstr;
do{
*here='\0'; /* terminate string */
/* Check whether this tool type is
commented out. Just ignore it in this case */
if (*tt) {
if (**tt=='(' || **tt==';')
continue;
strcpy(here,*tt); /* Add TT string */